﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLNH.MyLayouts;
using QLNH.QLNH_BUS_WS;

namespace QLNH.MyForms
{
    public partial class AdminSaleStatistic : FormUC
    {
        public AdminSaleStatistic(LayoutUC mainLayout)
        {
            InitializeComponent();
            _mainLayout = mainLayout;
            _formKey = FormKey.ADMIN_SALE_STATISTIC;
        }

        private int choose = 0;

        private void rbt_checkedChanged(object sender, EventArgs e)
        {
            RadioButton control = (RadioButton)sender;

            if (control != null)
            {
                int tag = Int32.Parse(control.Tag.ToString());
                choose = tag;
                switch (tag)
                {
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        dtp_start.Enabled = dtp_end.Enabled = rbt_date.Checked;
                        break;
                    default: break;
                }
            }
        }

        private void bt_viewStatistic_Click(object sender, EventArgs e)
        {
            QLNH_BUS_WebServiceSoapClient ws = new QLNH_BUS_WebServiceSoapClient();

            BillDTO[] bills = null;

            DateTime from, to;
            DateTime now = DateTime.Now;
            from = to = now;

            switch (choose)
            {
                case 0:
                    break;
                case 1:
                    {
                        int dayInWeek = now.DayOfWeek - DayOfWeek.Sunday;
                        from = DateTime.Now.AddDays(-dayInWeek);
                        to = now;
                    }
                    break;
                case 2:
                    {
                        from = DateTime.Now.AddDays(-now.Day + 1);
                        to = now;
                    }
                    break;
                case 3:
                    {
                        from = dtp_start.Value;
                        to = dtp_end.Value;
                    }
                    break;
                default: break;
            }

            if (choose == 0)
            {
                bills = ws.GetAllBill();
            }
            else
            {
                bills = ws.GetAllBillByDate(from, to);
            }

            BillDTOBindingSource.DataSource = bills;
            reportViewer.RefreshReport();
        }

        private void bt_back_Click(object sender, EventArgs e)
        {
            _mainLayout.SwitchForm(FormKey.ADMIN_STATISTICS);
        }


    }
}
